package com.dps.recommend.utils;

import com.dps.recommend.beans.DpsRequest;
import lombok.extern.slf4j.Slf4j;

@Slf4j(topic = "dpsRecLog")
public class LogUtils {

    /**
     * userId:6155971059086320149,sence:tabSquare,group:default,layer:merage,model:squareFilterMerage,modelName:融合过滤,modelGroup:default,message=%s
     */
    /**
     * 格式化日志
     *
     * @param dpsRequest
     * @param message
     * @return
     */
    private static String message(DpsRequest dpsRequest, String message) {
        return String.format("userId:%s,sence:%s,group:%s,layer:%s,model:%s,modelName:%s,modelGroup:%s,message=%s",
                dpsRequest.getRequest().getUserId(), dpsRequest.getRequest().getSence(),
                dpsRequest.getGroupName(), dpsRequest.getLayer().getLayerName(),
                dpsRequest.getRoad().getModel(), dpsRequest.getRoad().getModelName(),
                dpsRequest.getRoad().getGroupName(), message);
    }

    public static void info(DpsRequest dpsRequest, String message) {
        log.info(message(dpsRequest, message));
    }

    public static void error(DpsRequest dpsRequest, String message) {
        log.error(message(dpsRequest, message));

    }

    public static void warn(DpsRequest dpsRequest, String message) {
        log.warn(message(dpsRequest, message));

    }

    public static void debug(DpsRequest dpsRequest, String message) {
        if (dpsRequest.getRequest().getDebug()) {
            log.debug(message(dpsRequest, message));
        }
    }
}
